<!DOCTYPE html>
<html>
<head>
    {include file="Public:header" /}
    <link rel="stylesheet" href="__STATIC__/admin/assets/css/view.css"/>
    <link rel="icon" href="__STATIC__/admin/favicon.ico">
    <title>权限配置</title>    
    <style type="text/css">
        .layui-input-block{margin-left:0px; }
    </style>
</head>
<body class="layui-view-body">
<div class="layui-content">
    <div class="layui-page-header">
        <div class="pagewrap">
            <span class="layui-breadcrumb">
              <a href="">首页</a>
              <a href="">用户</a>
              <a><cite>商品管理</cite></a>
            </span>
            <h2 class="title">商品管理</h2>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-card">
            <div class="layui-card-body">
                <table class="layui-table">
                    <colgroup>
                        <col width="50">
                        <col width="50">
                        <col width="200">
                        <col width="200">
                        <col width="80">
                        <col width="50">
                        <col width="100">
                        <col>
                        <col>
                    </colgroup>
                <thead>
                    <tr>
                        <td>排序</td>
                        <th>id</th>
                        <th>商品名称</th>
                        <th>所属分类</th>
                        <th>略图</th>
                        <th>数量</th>
                        <th>价格</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr> 
                </thead>
                <tbody>
                    {volist name="detail" id="vo"}
                    <tr>
                        <input type="hidden" name="did" value="{$vo.id}">
                        <td><input type="text" name="sort" value="{$vo.sort}" style="width: 35px;text-align: center;"></td>
                        <td>{$vo.id}</td>
                        <td>{$vo.name}</td>
                        <td>{$vo.title}</td>
                        <td><img src="{$vo.img}" width="75" alt="{$vo.name}"></td>
                        <td>{$vo.sum}</td>
                        <td style="color: #ff0000">{$vo.price}元</td>
                        <td>
                            <form class="layui-form">
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <input type="checkbox" value="{$vo.status}" {eq name="vo:status" value="1" }checked{/eq} title="{$vo.id}" lay-skin="switch" lay-text="开启|关闭">
                                    </div>
                                </div>
                            </form>
                        </td>
                        <td>
                            <div class="layui-btn-group">
                                <button class="layui-btn layui-btn-primary layui-btn-sm" onclick="hc_move('修改栏目','{:url("detail/edit",["id"=>$vo["id"]])}')">
                                    <i class="layui-icon">&#xe65f;</i>
                                </button>
                                <button class="layui-btn layui-btn-primary layui-btn-sm" onclick="hc_edit('修改栏目','{:url("detail/edit",["id"=>$vo["id"]])}')">
                                    <i class="layui-icon">&#xe642;</i>
                                </button>
                                <button class="layui-btn layui-btn-primary layui-btn-sm" onclick="hc_del('','{:url("detail/del",["id"=>$vo["id"]])}')">
                                    <i class="layui-icon">&#xe640;</i>
                                </button>
                            </div>
                        </td>
                    </tr>
                    {/volist}
                </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{include file="Public:footer" /}
<script>
window.onload = function(){
    layui.use(['form','layer'], function(){
        var form = layui.form;
        var layer = layui.layer;   
        form.on('switch', function(data) {
            $(data.elem).val(this.checked ? 1 : 0);
            var id = data.elem.title;
            console.log(data.elem.value);
            $.ajax({
                method: 'post',
                url: '{:url("detail/status")}',
                data: {
                    id: id,
                },
                dataType: 'json',
                success: function(res) {
                    if(res.code == '1001'){
                        layer.msg(res.data);
                        setTimeout(function () {
                            window.location.href = '';
                        },2000)
                    }else{
                        layer.msg('修改失败 ');
                    }
                },
                error:function () {
                    layer.msg('状态修改失败 ');
                }
            })
        });
        // 栏目排序 fid
        $("input[name='sort']").each(function () {
            $(this).on('change',function () {
                var did = $(this).parents('td').siblings("input[name='did']").val();
                var sort = $(this).val();
                $.ajax({
                    method: 'post',
                    url: '{:url("detail/sort")}',
                    data: {
                        id: did,
                        sort: sort,
                    },
                    dataType: 'json',
                    success: function(res) {
                        if(res.code == '1001'){
                            layer.msg(res.data);
                        }else{
                            layer.msg('修改失败 ');
                        }
                    },
                    error:function (err) {
                        layer.msg('修改失败'+err);
                    }
                });
            });
        });
    });
}
</script>
</body>
</html>